declare let cacheGet: any;
module MC {
	class USER {
		public constructor() {
		}
		/** 
		 * 获取用户类型
		 */
		public getType(): USERTYPE {
			return MC.USERTYPE.Type_gongsi_gongchang;
			let info = cacheGet('userInfo');
			if (!info) {
				return null;
			} else {
				return info.type;
			}
		}
		private uidArray: any = [];

		private _userEvent: any = [];
		/** 获取用户信息 */
		public getInfo(id: string = 'my', fun: Function = null) {

			if (this.uidArray[id]) {
				fun && fun(this.uidArray[id]);
				return;
			}
			window.addEventListener("getInfo" + id, (event) => {
				fun && fun(this.uidArray[id]);
			});
			if (this._userEvent[id]) {
				return;
			}
			this._userEvent[id] = true;
			MC.api('getuserinfo', {
				uid: id
			}, (json: any) => {
				this.uidArray[id] = json;
				var myEvent = new Event("getInfo" + id);
				if (window.dispatchEvent) {
					window.dispatchEvent(myEvent);
				} else {
					(<any>window).fireEvent(myEvent);
				}
				///	fun&&fun(json);
			});
		}

		/***
		 * 本地缓存的用户信息
		*/
		get info(){
			return cacheGet('userInfo');
		}

	}
	export let user = new USER();
	export enum USERTYPE {
		Type_yuangong = 1,////1个人用户
		Type_gongsi = 2,///2公司；
		Type_gongchang = 3,///3工厂
		Type_gongsi_gongchang = 4////4企业
	}
}